#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){

    ofSetFrameRate(30);
    //ofSetLogLevel(OF_LOG_VERBOSE);


    //Setup the SMS manager with the gnokii input/output directory and set to check the directory every one second.
    smsStream.setup("/tmp/sms", 1.0f);

    //----------------------------------------------------------------------
    //The following lines offer optional SQLite support.  They are optional.

    //Load previous SMSes from the SMS database and place in the SMS manager.  You need to use a full path for this.
    smsDB.load("/home/rigger/test.db",&smsStream);

    //Set the SMS manager to save its contents to the database every 5 seconds.
    smsDB.setAutoSave("/home/rigger/test.db",&smsStream,5.0f);

    //----------------------------------------------------------------------

}

//--------------------------------------------------------------
void testApp::update(){

}

//--------------------------------------------------------------
void testApp::draw(){

    //draw on screen view of the SMS manager queues.
    smsStream.draw(0,0);

}

//--------------------------------------------------------------
void testApp::keyPressed(int key){

    //Mark the next SMS in the unread queue as read.
    if (key == 'r'){
        if(smsStream.bUnreadSMS()){
            smsStream.getNextUnreadSMS();
        };
    }


    //----------------------------------------------------------------------
    //The following lines offer optional SQLite support.  They are optional.

    //Export the database to a text file.
    if (key == 'e'){
        smsDB.exportToFile("/home/rigger/test.db", "export.txt");
    }

    //Manually trigger a save of the SMS manager to the database.
    if (key == 's'){
        smsDB.save("/home/rigger/test.db",&smsStream);
    }
    //----------------------------------------------------------------------

}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//This POCO event is triggered on receiving an SMS.  This function must be defined.
void ofxSMS::newSMSEvent(ofxSMSEventArgs &e){

    //Get the contents of the message identified by the 'id' event parameter.
    ofxSMSMessage newMsg = getSMS(e.id);
    printf("New Message Received: %s\n",newMsg.text.c_str());

    //Send a reply SMS to the sender.
    send(newMsg.from, "Thanks for your message!");

}
